import 'package:flutter/material.dart';
import 'package:gold/base/provider_scaffold.dart';
import 'package:gold/ui/my/settings/name/name_viewmodel.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';
import 'package:provider/provider.dart';

/// @description: 修改昵称
/// @author tangzhentao
/// @created at 21:11 2025/1/1

class NamePage extends StatelessWidget {
  const NamePage({super.key});

  @override
  Widget build(BuildContext context) {
    return ProviderScaffold<NameViewmodel>(
      resizeToAvoidBottomInset: false,
      appBar: (_) => xfgAppbar(title: '修改昵称'),
      backgroundColor: XfgColor.white,
      model: NameViewmodel(),
      builder: (ctx, name) => Column(
        children: [
          strokeHeightContainer,
          Container(
            margin: EdgeInsets.fromLTRB(XfgSize().size10, XfgSize().size18, XfgSize().size10, XfgSize().size34),
            height: XfgSize().size52,
            padding: EdgeInsets.symmetric(horizontal: XfgSize().size20),
            alignment: Alignment.center,
            decoration: loginTextFieldDecoration,
            child: TextField(
              keyboardType: TextInputType.text,
              style: TextStyle(fontSize:XfgSize().text18, color: XfgColor.text1D),
              maxLines: 1,
              controller: name.nameController,
              focusNode: name.nameNode,
              onChanged: name.phoneChanged,
              onEditingComplete: () {},
              decoration: InputDecoration(
                  isCollapsed: true,
                  border: InputBorder.none,
                  contentPadding: EdgeInsets.zero,
                  hintStyle: TextStyle(fontSize: XfgSize().text18, color: XfgColor.text3),
                  hintText: '请输入昵称'
              ),
            ),
          ),
          Builder(builder: (ctx) {
            final canClick = ctx.select<NameViewmodel, bool>((k) => k.canClick);
            return TextButton(
              onPressed: canClick? name.submit:null,
              style: xfgButtonStyle(Size(XfgSize().size342, XfgSize().size50), radius: XfgSize().size50),
              child: XfgText('提交', color: XfgColor.white, fontSize: XfgSize().text18),
            );
          })
        ],
      ),
    );
  }
}
